package cn.cheegon.blog.common.security.config;

import cn.cheegon.blog.common.security.DynamicSecurityService;
import cn.cheegon.blog.service.UmsAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.core.userdetails.UserDetailsService;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Desc:
 * @Author: cheegon
 * @Date: Create in 2024/6/11  下午2:47
 */
@Configuration
public class AdminSecurityConfig {

    @Autowired
    private UmsAdminService adminService;

    @Bean
    public UserDetailsService userDetailsService() {
        //获取登录用户信息
        return username -> adminService.loadUserByUsername(username);
    }

    @Bean
    public DynamicSecurityService dynamicSecurityService() {
        return () -> {
            Map<String, ConfigAttribute> map = new ConcurrentHashMap<>();
//            List<UmsResource> resourceList = resourceService.listAll();
//            for (UmsResource resource : resourceList) {
//                map.put(resource.getUrl(), new org.springframework.security.access.SecurityConfig(resource.getId() + ":" + resource.getName()));
//            }
            return map;
        };
    }
}
